package com.rfs.suanfa;

import com.alibaba.fastjson.JSON;

/**
 * @author renfushuai
 * @date 2022/2/8
 */
public class 删除链表重复元素 {
    public static void main(String[] args) {
        // 1->2->2->3
        ListNode l4 = new ListNode(3, null);
        ListNode l3 = new ListNode(2, l4);
        ListNode l2 = new ListNode(2, l3);
        ListNode l1 = new ListNode(1, l2);
        System.out.println(JSON.toJSONString(deleteDuplicates(l1)));

    }

    public static ListNode deleteDuplicates(ListNode head) {
        if (head == null) {
            return head;
        }
        ListNode cur = head;
        while (cur.next != null) {
            if (cur.val == cur.next.val) {
                cur.next = cur.next.next;
            } else {
                cur = cur.next;
            }
        }
        return head;
    }
}
